//
//  EJSGoodsCCell.m
//  EnjoyShoppingStreet
//
//  Created by lifayu on 2017/12/20.
//  Copyright © 2017年 lifayu. All rights reserved.
//

#import "EJSGoodsCCell.h"
#import "EJSGoodsModel.h"
#import "EJSAddCartButton.h"
@implementation EJSGoodsCCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setGoodsModel:(EJSGoodsModel *)goodsModel{
    self.model = goodsModel;
    if (goodsModel.addCartNum.intValue == 0) {
        self.addedCountLabel.text = @"";
    }else {
        self.addedCountLabel.text = [NSString stringWithFormat:@"%d", goodsModel.addCartNum.intValue / goodsModel.minToBuy.intValue];
    }
    if (goodsModel.unit && goodsModel.unit.length > 0) {
        self.pakageLabel.text = [NSString stringWithFormat:@"x %@/%@", goodsModel.minToBuy, goodsModel.unit];
    }else {
         self.pakageLabel.text = [NSString stringWithFormat:@"x %@", goodsModel.minToBuy];
    }
    
    if (self.isHorizontal) {
        [self.addedCountLabel setHidden:YES];
    }

    self.goodsNameLabel.text = goodsModel.spuName;
    self.priceLabel.text = [NSString stringWithFormat:@"€ %@",goodsModel.price];
    [self.goodsImageView setImageWithUrl:goodsModel.cover];
}

- (IBAction)addToCartAction:(EJSAddCartButton *)sender {
    [sender setSelected:YES];
    [sender startButtonAnimation];
    [sender setSelected:NO];
    if ([self.delegate respondsToSelector:@selector(goodsCell:addGoodsNum:)]) {
        [self.delegate goodsCell:self addGoodsNum: self.model];
    }
}

@end
